package br.com.consigsys.controller;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;

import org.apache.commons.collections.MapUtils;

import br.com.consigsys.util.search.MapSearchFilterLazyMapFactory;
import br.com.consigsys.util.search.SearchDTO;
import br.com.consigsys.util.search.SearchFilter;
import br.com.consigsys.util.search.SearchFilterType;


@ManagedBean
@SessionScoped
public class SearchHelper implements Serializable{
	
	private static final long serialVersionUID = 4035381202770312567L;
	private SearchDTO searchDTO;
	private Map<String,Map<String, SearchFilter>> filtersMap;
	
	@SuppressWarnings("unchecked")
	@PostConstruct
	public void init() {
		this.setSearchDTO(new SearchDTO());
		this.filtersMap = MapUtils.lazyMap(
				new HashMap<String, Map<String, SearchFilter>>(),
				new MapSearchFilterLazyMapFactory());
		
		
	}
	
	public void reset(ActionEvent event){
		this.filtersMap.clear();
		
	}
	
	public SearchFilterType[] getTypes(){
		
		return SearchFilterType.values();
	}

	/**
	 * @return the searchDTO
	 */
	public SearchDTO getSearchDTO() {
		return searchDTO;
	}

	/**
	 * @param searchDTO the searchDTO to set
	 */
	public void setSearchDTO(SearchDTO searchDTO) {
		this.searchDTO = searchDTO;
	}

	/**
	 * @return the filtersMap
	 */
	public Map<String,Map<String, SearchFilter>> getFiltersMap() {
		return filtersMap;
	}

	/**
	 * @param filtersMap the filtersMap to set
	 */
	public void setFiltersMap(Map<String,Map<String, SearchFilter>> filtersMap) {
		this.filtersMap = filtersMap;
	}
	
	
}
